
import { Provide, Inject } from '@midwayjs/core';
import { TeamDao } from '@dao/team.dao';
import { CreateTeamDto, UpdateTeamDto, QueryTeamDto, teamTeacherDto } from '@dto/team.dto';
import { DownloadExcelService } from '../service/common/downloadExcel';
@Provide()
export class TeamService {
  @Inject()
  teamDao: TeamDao;
  @Inject()
  downloadExcelService: DownloadExcelService;
  // 创建
  async create(body: CreateTeamDto) {
    return await this.teamDao.create(body);
  }
  // 获取列表
  async list(query: QueryTeamDto) {
    return await this.teamDao.list(query);
  }
  // 获取详情
  async detail(teamId: string) {
    return await this.teamDao.detail(+teamId);
  }
  // 修改
  async update(body: UpdateTeamDto) {
    return await this.teamDao.update(body);
  }
  // 删除
  async remove(teamIds: Array<number>) {
    return await this.teamDao.remove(teamIds);
  }

  // 创建队伍教师
  async createTeamTeacher(teamTeacherDto: teamTeacherDto) {
    return await this.teamDao.createTeamTeacher(teamTeacherDto);
  }

  //获取
  async get(teacherId: number) {
    return await this.teamDao.getCrrentTeam(teacherId);
  }

  // 导出
  async export(queryParams: QueryTeamDto) {
    const headers = [
      { label: '队伍ID', prop: 'teamId' },
      { label: '所属分组ID', prop: 'groupId' },
      { label: '毕设名称', prop: 'teamName' },
      { label: '作品链接', prop: 'teamLink' },
      { label: '作品简介', prop: 'summary' },
      { label: '状态（0未选择 1已选择）', prop: 'selectFlag' },
      { label: '备注', prop: 'remark' },
      { label: '状态（0正常 1停用）', prop: 'status' }
    ];
    const { rows } = (await this.teamDao.list(queryParams)).data;
    return this.downloadExcelService.downloadExcel({
      headers,
      data: rows,
      sheetName: 'Team信息',
    });
  }
}
